using System;
using System.Collections;

using DesignByContract;

namespace Outcoding.GraphGenerator.Entities {
    public class SeriesCollection : CollectionBase {

        /// <summary>
        /// Default Constructor
        /// </summary>
        public SeriesCollection() {
        }

        /// <summary>
        /// This index into Series Collection.
        /// </summary>
        /// <param name="index">The index of the Series.</param>
        /// <returns>A Series object located in the given index.</returns>
        public Series this[int index] {
            get {
                return (Series)List[index];
            }
            set {
                List[index] = value;
            }
        }

        /// <summary>
        /// Add new Series to this collection.
        /// </summary>
        /// <param name="value">Series to add.</param>
        /// <returns>Index of the new value added.</returns>
        public int Add(Series value) {
            return List.Add(value);
        }

        /// <summary>
        /// Find the index for a given Series.
        /// </summary>
        /// <param name="value">Series to look for.</param>
        /// <returns>The index assign to the Series object.</returns>
        public int IndexOf(Series value) {
            return List.IndexOf(value);
        }

        /// <summary>
        /// Add new Series to this collection in the specified index.
        /// </summary>
        /// <param name="index">The index to place the Series.</param>
        /// <param name="value">The Series object to add.</param>
        public void Insert(int index, Series value) {
            List.Insert(index, value);
        }

        /// <summary>
        /// Remove a Series from this collection.
        /// </summary>
        /// <param name="value">Series object to remove.</param>
        public void Remove(Series value) {
            List.Remove(value);
        }

        /// <summary>
        /// Indicates if a Series exists in this collection.
        /// </summary>
        /// <param name="value">The Series to search.</param>
        /// <returns>A Boolean value indicating whether or not the Series exists in this collection.</returns>
        public bool Contains(Series value) {
            // If value is not of type Series, this will return false.
            return List.Contains(value);
        }

        /// <summary>
        /// Check Type on insert.
        /// </summary>
        protected override void OnInsert(int index, object value) {
            base.OnInsert(index, value);
            if (value.GetType() != typeof(Series))
                throw new ArgumentException("value must be of type Series", "value");
        }

        /// <summary>
        /// Check type on removal.
        /// </summary>
        protected override void OnRemove(int index, object value) {
            if (value.GetType() != typeof(Series))
                throw new ArgumentException("value must be of type Series.", "value");
        }

        /// <summary>
        /// Check type on set.
        /// </summary>
        protected override void OnSet(int index, object oldValue, object newValue) {
            if (newValue.GetType() != typeof(Series))
                throw new ArgumentException("newValue must be of type Series.", "newValue");
        }

        /// <summary>
        /// Check type on validate.
        /// </summary>
        protected override void OnValidate(object value) {
            if (value.GetType() != typeof(Series))
                throw new ArgumentException("value must be of type Series.");
        }
    }
}